from django.db import models
from datetime import datetime

from django.contrib.auth.models import AbstractUser


class UserProfile(AbstractUser):
    """
    用户认证信息,这些信息属于用户真实信息
    """
    nick_name = models.CharField(max_length=200, verbose_name="昵称", default="outback", help_text='昵称')
    name = models.CharField(max_length=30, null=False, blank=False, verbose_name="姓名", help_text='姓名')
    birthday = models.DateField(null=True, blank=True, verbose_name="出生日期", help_text='出生日期')
    mobile = models.CharField(null=True, blank=True, max_length=11, verbose_name="电话", help_text='电话')
    gender = models.CharField(null=True, blank=True, choices=(('male', '男'), ("female", '女')), max_length=6,
                              default='male', verbose_name="性别", help_text='性别')
    head_image = models.ImageField(upload_to='image/%Y%m', default='image/default.png', max_length=300,
                                   verbose_name="头像", help_text='头像')
    surface_image = models.ImageField(upload_to='image/%Y%m', default='image/default.png', max_length=300,
                                      verbose_name="封面图", help_text='封面图')
    followed_count = models.IntegerField(verbose_name="关注他的人的数量", default=0, blank=False, null=False,
                                         help_text='关注他的人的数量')
    following_count = models.IntegerField(verbose_name="他关注的人的数量", default=0, blank=False, null=False,
                                          help_text='他关注的人的数量')

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class VerifyCode(models.Model):
    """验证码"""
    code = models.CharField(max_length=6, verbose_name='验证码',help_text='验证码')
    mobile = models.CharField(max_length=11, verbose_name='手机号',help_text='手机号')
    add_time = models.DateTimeField(default=datetime.now, verbose_name='添加时间',help_text='添加时间')

    class Meta:
        verbose_name = '验证码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.code
